clear all
set more off
cap log close
cap set scheme stcolor


do "/Users/alisatns/Dropbox/Projects/Canada - Capital Gains/RESTAT Replication Package/Do files/0_Set_Directories.do"

****************************************************************************
* This do-file 
* 
* Prepares graphs
* 
****************************************************************************


*---------------------- Figure B1  (number of tax filers in LAD)  -------------------*




clear
****************************************************************************
 import excel "$dir_outputs/RESTAT_Online_Appendix_B_for_release.xlsx", sheet("Figure_B1") firstrow
****************************************************************************



sort year
gen total_diff=rtotal[_n]-rtotal[_n-1] 
gen total_diff_p=(rtotal[_n]-rtotal[_n-1])/rtotal[_n-1] *100


twoway connected  rtotal year ,  xline(1986 1989,  lcolor(red))  ylabel( 15000000 (5000000)30000000, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1983 1986 1989 1992 1995 1998 2001 2004 2007 2010 2013 2016)  ytitle("number of tax filers") 
graph export  "$dir_graphs/Figure_B1a.pdf", replace

twoway connected  total_diff year ,  xline(1986 1989,  lcolor(red))  ylabel(, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1983 1986 1989 1992 1995 1998 2001 2004 2007 2010 2013 2016) ytitle("absolute change in tax filers")
graph export  "$dir_graphs/Figure_B1b.pdf", replace

twoway connected  total_diff_p year ,  xline(1986 1989,  lcolor(red))  ylabel(, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1983 1986 1989 1992 1995 1998 2001 2004 2007 2010 2013 2016) ytitle("% change in tax filers")
graph export  "$dir_graphs/Figure_B1c.pdf", replace


*---------------------- Figure E1 + E2  -------------------*


clear
****************************************************************************
 import excel "$dir_outputs/RESTAT_Online_Appendix_E_for_release.xlsx", sheet("Figure_E1") firstrow
****************************************************************************
sort year
tempfile temp
save `temp', replace
clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_E_for_release.xlsx", sheet("Figure_E2") firstrow
****************************************************************************
sort year
merge year using `temp'
drop _merge


sort  year
merge n:1 year using "$dir_outputs/inflation.dta"
keep if _merge==1 | _merge==3
drop _merge

sort  year
merge n:1 year using "$dir_outputs/TSEIndex_merge.dta"
keep if _merge==1 | _merge==3
drop _merge
lab var tsx "S&P TSE Index"
replace tsx=tsx*cpi_to2016



foreach var in  clkgxi_dummy_wgt clkgxi_dummy_morethan1k_wgt  clkgxi_dummy_lessthan1k_wgt {
replace `var'=`var'*100
}


*
foreach var in rclkgxi_wgt rpos_clkgxi_wgt rpos_clkgxi_morethan1k_wgt rpos_clkgxi_lessthan1k_wgt    tsx{
replace `var'=`var'/1.5
}

lab var tsx "S&P TSE Index (1993 $)" 
lab var rclkgxi_wgt "capital gains (1993 $)"
lab var rpos_clkgxi_wgt "capital gains (1993 $)"
lab var rclkgxi_wgt "capital gains (1993 $)"
lab var rpos_clkgxi_wgt "capital gains (1993 $)"
lab var rpos_clkgxi_lessthan1k_wgt "capital gains (1993 $)"
lab var rpos_clkgxi_morethan1k_wgt "capital gains (1993 $)"

lab var clkgxi_dummy_wgt "% with positive net capital gains"
lab var clkgxi_dummy_morethan1k_wgt "% with net capital gains >$K (1982 $)"
lab var clkgxi_dummy_lessthan1k_wgt "% with net capital gains <$1K (1982 $)"



*********** Extensive margin graphs: Canada only ***********


local var rclkgxi_wgt
twoway connected `var' year, xline(1985 1994, lcolor(red) lpattern(-)) ylabel(0(500)2000, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(5000)20000, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E1a.pdf", replace


local var  clkgxi_dummy_wgt   
*
twoway connected  `var' year, xline(1985 1994, lcolor(red) lpattern(-))  ylabel(0(2.5)13, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2500)13000, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E1b.pdf", replace
*

local var rpos_clkgxi_wgt
twoway connected  `var' year, xline(1985 1994, lcolor(red) lpattern(-)) ylabel(0(5000)20000, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(5000)20000, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E1c.pdf", replace




local var rpos_clkgxi_lessthan1k_wgt
twoway connected  `var' year, xline(1985 1994, lcolor(red) lpattern(-))ylabel(0(100)1100, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(1000)11000, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E2a.pdf", replace




local var rpos_clkgxi_morethan1k_wgt
twoway connected  `var' year, xline(1985 1994, lcolor(red) lpattern(-)) ylabel(0(5000)30000, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(5000)30000, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E2b.pdf", replace



local var clkgxi_dummy_morethan1k_wgt
*
twoway connected  `var' year, xline(1985 1994, lcolor(red) lpattern(-)) ylabel(0(2.5)12.5, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2500)12500, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E2d.pdf", replace


*
local var clkgxi_dummy_lessthan1k_wgt
twoway connected  `var' year, xline(1985 1994, lcolor(red) lpattern(-))  ylabel(0(2.5)12.5, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2500)12500, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E2c.pdf", replace
*




*---------------------- Figure E3  (time series by age)  -------------------*


clear
****************************************************************************
 import excel "$dir_outputs/RESTAT_Online_Appendix_E_for_release.xlsx", sheet("Figure_E3") firstrow
****************************************************************************

destring rclkgxi_some6, replace
replace rclkgxi_some6=rclkgxi_some6/1.5
replace rclkgxi_none6=rclkgxi_none6/1.5

twoway connected rclkgxi_some6 year if age_group==1,  title("") xline(1985 1994, lcolor(red) lpattern(-))  xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || connected rclkgxi_none6 year if age_group==1 , msymbol(Oh)   graphregion(color(white)) bgcolor(white) ytitle("average capital gains  (1993 $)") xtitle("") legend(order(1 "some" 2 "none"   ) pos(5) ring(0) col(1))
graph export  "$dir_graphs/Figure_E3g.pdf", replace


twoway connected rclkgxi_some6 year if age_group==2, title("") xline(1985 1994, lcolor(red) lpattern(-))  xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || connected rclkgxi_none6 year if age_group==2 , msymbol(Oh)   graphregion(color(white)) bgcolor(white) ytitle("average capital gains  (1993 $)") xtitle("") legend(order(1 "some" 2 "none"   ) pos(5) ring(0) col(1))
graph export  "$dir_graphs/Figure_E3h.pdf", replace


twoway connected rclkgxi_some6 year if age_group==3, title("") xline(1985 1994, lcolor(red) lpattern(-))  xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || connected rclkgxi_none6 year if age_group==3 , msymbol(Oh)   graphregion(color(white)) bgcolor(white) ytitle("average capital gains  (1993 $)") xtitle("") legend(order(1 "some" 2 "none"   ) pos(5) ring(0) col(1))
graph export  "$dir_graphs/Figure_E3i.pdf", replace

drop rnone1_past6

foreach var in 2 4 6 {
gen rnone1_past`var'=rsome1-rsome1_past`var'
gen rsome1perc_past`var'=rsome1_past`var'/rsome1*100
gen rnone1perc_past`var'=rnone1_past`var'/rsome1*100
gen rsome1_2_past`var'=rsome1_past`var'/rtotal*100
gen rnone1_2_past`var'=rnone1_past`var'/rtotal*100
}
foreach var in 3 5 7{
gen rnone_past`var'= rtotal-rsome_past`var'
}

replace rsome1=rsome1/rtotal*100

*
twoway   connected rsome1_2_past6 year if year>=1988 & age_group==1, title("") ylabel(0(2)20) xline(1985 1994, lcolor(red) lpattern(-)) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || connected rnone1_2_past6 year if year>=1988  & age_group==1, msymbol(Oh) || line rsome1 year if year>=1982 & age_group==1, lcolor(gray) lpattern(-)  graphregion(color(white)) bgcolor(white) ytitle("% individuals ") xtitle("") legend(order(1 "some past 6 years " 2 "none past 6 years" 3 "all"  ) pos(1) ring(0) col(1)) 
graph export  "$dir_graphs/Figure_E3d.pdf", replace
twoway   connected rsome1_2_past6 year if year>=1988 & age_group==2, title("") ylabel(0(2)20) xline(1985 1994, lcolor(red) lpattern(-)) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || connected rnone1_2_past6 year if year>=1988  & age_group==2, msymbol(Oh) || line rsome1 year if year>=1982 & age_group==2, lcolor(gray) lpattern(-)  graphregion(color(white)) bgcolor(white) ytitle("% individuals ") xtitle("") legend(order(1 "some past 6 years " 2 "none past 6 years" 3 "all"  ) pos(1) ring(0) col(1)) 
graph export  "$dir_graphs/Figure_E3e.pdf", replace
twoway   connected rsome1_2_past6 year if year>=1988 & age_group==3, title("") ylabel(0(2)20) xline(1985 1994, lcolor(red) lpattern(-)) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || connected rnone1_2_past6 year if year>=1988  & age_group==3, msymbol(Oh) || line rsome1 year if year>=1982 & age_group==3, lcolor(gray) lpattern(-)  graphregion(color(white)) bgcolor(white) ytitle("% individuals ") xtitle("") legend(order(1 "some past 6 years " 2 "none past 6 years" 3 "all"  ) pos(1) ring(0) col(1)) 
graph export  "$dir_graphs/Figure_E3f.pdf", replace



replace rsome_past3=rsome_past3/rtotal*100
replace rsome_past5=rsome_past5/rtotal*100
replace rsome_past7=rsome_past7/rtotal*100
twoway   connected rsome_past3 year if year>=1984 & age_group==1,  xline(1985 1994, lcolor(red) lpattern(-)) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || connected rsome_past5 year if year>=1986 & age_group==1 , msymbol(Oh) || connected rsome_past7 year if year>=1988 & age_group==1, msymbol(X) graphregion(color(white)) bgcolor(white) ytitle("% individuals ") xtitle("") legend(order(1 "some past 3 years " 2 "some past 5 years" 3 " some past 7 years"  ) pos(5) ring(0) col(1)) 
graph export  "$dir_graphs/Figure_E3a.pdf", replace


twoway   connected rsome_past3 year if year>=1984 & age_group==2,  xline(1985 1994, lcolor(red) lpattern(-)) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || connected rsome_past5 year if year>=1986 & age_group==2 , msymbol(Oh) || connected rsome_past7 year if year>=1988 & age_group==2, msymbol(X) graphregion(color(white)) bgcolor(white) ytitle("% individuals ") xtitle("") legend(order(1 "some past 3 years " 2 "some past 5 years" 3 " some past 7 years"  ) pos(5) ring(0) col(1)) 
graph export  "$dir_graphs/Figure_E3b.pdf", replace

twoway   connected rsome_past3 year if year>=1984 & age_group==3,  xline(1985 1994, lcolor(red) lpattern(-)) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || connected rsome_past5 year if year>=1986 & age_group==3 , msymbol(Oh) || connected rsome_past7 year if year>=1988 & age_group==3, msymbol(X) graphregion(color(white)) bgcolor(white) ytitle("% individuals ") xtitle("") legend(order(1 "some past 3 years " 2 "some past 5 years" 3 " some past 7 years"  ) pos(5) ring(0) col(1)) 
graph export  "$dir_graphs/Figure_E3c.pdf", replace


*---------------------- Figure E4  (time series by marital status)  -------------------*


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_E_for_release.xlsx", sheet("Figure_E4") firstrow
****************************************************************************


sort  year
merge n:1 year using "$dir_outputs/inflation.dta"
keep if _merge==1 | _merge==3
drop _merge

sort  year
merge n:1 year using "$dir_outputs/TSEIndex_merge.dta"
keep if _merge==1 | _merge==3
drop _merge
lab var tsx "S&P TSE Index"
replace tsx=tsx*cpi_to2016

foreach var in rclkgxi_wgt rpos_clkgxi_wgt tsx {
replace `var'=`var'/1.5
}

replace clkgxi_dummy_wgt=clkgxi_dummy_wgt*100
lab var clkgxi_dummy_wgt "% with positive net capital gains"
*
lab var rclkgxi_wgt "capital gains (1993 $)"
lab var rpos_clkgxi_wgt "capital gains (1993 $)"
*
lab var tsx "S&P TSE Index (1993 $)" 


twoway connected rclkgxi_wgt year if married==0,   xline(1985  1994 , lpattern(-) lcolor(red)) ylabel(0(200)2000, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2000)20000, axis(2)  ang(h)) legend(  pos(6) ring(1) col(2)) 
graph export  "$dir_graphs/Figure_E4a.pdf", replace
twoway connected rclkgxi_wgt year if married==1,   xline(1985  1994 , lpattern(-) lcolor(red)) ylabel(0(200)2000, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2000)20000, axis(2)  ang(h)) legend(  pos(6) ring(1) col(2)) 
graph export  "$dir_graphs/Figure_E4d.pdf", replace


* Intensive:
foreach var in  rpos_clkgxi_wgt {

twoway connected  `var' year if married==0,    xline(1985  1994 , lpattern(-) lcolor(red)) ylabel(0(2000)20000, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2000)20000, axis(2)  ang(h)) legend(  pos(6) ring(1) col(2)) 
graph export  "$dir_graphs/Figure_E4b.pdf", replace
twoway connected  `var' year if married==1,    xline(1985  1994 , lpattern(-) lcolor(red)) ylabel(0(2000)20000, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2000)20000, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E4e.pdf", replace

}

* Extensive margin
local var  clkgxi_dummy_wgt   
*
twoway connected  `var' year if married==0,  xline(1985  1994 , lpattern(-) lcolor(red))  ylabel(0(2.5)20, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2500)20000, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E4c.pdf", replace 
*
twoway connected  `var' year if married==1,   xline(1985  1994 , lpattern(-) lcolor(red))  ylabel(0(2.5)20, ang(h)) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2500)20000, axis(2)  ang(h)) legend( col(2) ring(1) pos(6))
graph export  "$dir_graphs/Figure_E4f.pdf", replace
*



*---------------------- Figure E5 (a + b)  -------------------*



clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_E_for_release.xlsx", sheet("Figure_E5") firstrow
****************************************************************************


lab var log_clkgxi_wgt "log(capital gains in 1993$)"
lab var ihs_clkgxi_wgt "asinh(capital gains in 1993$)"

foreach var in   ihs_clkgxi_wgt {

twoway connected  `var' year if year>=1990 & year<=1999 & cg_8593==1 , color(navy) lpattern(.) msymbol(X) msize(1.5) ///
|| connected  `var' year if year>=1990 & year<=1999 & cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(1) ///
|| connected  `var' year if year>=1990 &  year<=1999 & cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(1)  ///
|| connected  `var' year if year>=1990 &  year<=1999 & cg_8593==4, color(blue)msymbol(T) msize(1) ///
|| connected  `var' year if year>=1990 &  year<=1999 &  cg_8593==5, color(ebblue) msymbol(S)  msize(1)  msymbol(D) xline(1994 ,lcolor(red))  ///
 graphregion(color(white)) bgcolor(white) xlabel(  1990 1992  1994 1996 1998  2000) legend(order(1 "133K+" 2 "100K-133K" 3 "67K-100K" 4 "33.33K-67K" 5 "17K-33K"   ) ring(1) pos(6) col(6)) ylabel(1(0.5)6)
graph export  "$dir_graphs//Figure_E5a.pdf", replace

}


foreach var in   log_clkgxi_wgt {

twoway connected  `var' year if year>=1990 & year<=1999 & cg_8593==1 , color(navy) lpattern(.) msymbol(X) msize(1.5) ///
|| connected  `var' year if year>=1990 & year<=1999 & cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(1) ///
|| connected  `var' year if year>=1990 &  year<=1999 & cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(1)  ///
|| connected  `var' year if year>=1990 &  year<=1999 & cg_8593==4, color(blue)msymbol(T) msize(1) ///
|| connected  `var' year if year>=1990 &  year<=1999 &  cg_8593==5, color(ebblue) msymbol(S)  msize(1)  msymbol(D) xline(1994 ,lcolor(red))  ///
 graphregion(color(white)) bgcolor(white) xlabel(  1990 1992  1994 1996 1998  2000) legend(order(1 "133K+" 2 "100K-133K" 3 "67K-100K" 4 "33.33K-67K" 5 "17K-33K"   ) ring(1) pos(6) col(5)) ylabel(6.5(0.5)10)
graph export  "$dir_graphs//Figure_E5b.pdf", replace

}


*---------------------- Figure E5 (c+d)  -------------------*


* Step 1: Import Data 
clear
import excel "$dir_outputs/Canada_TSE_index_GSPTSE.xlsx", sheet("GSPTSE") firstrow
drop in 438
destring Open High Low Close AdjClose Volume, replace

* Step 2: Create Time Variables
gen year = 1985 in 1/12
replace year = 1986 in 13/24
replace year = 1987 in 25/36
replace year = 1988 in 37/48
replace year = 1989 in 49/60
replace year = 1990 in 61/72
replace year = 1991 in 73/84
replace year = 1992 in 85/96
replace year = 1993 in 97/108
replace year = 1994 in 109/120
replace year = 1995 in 121/132
replace year = 1996 in 133/144
replace year = 1997 in 145/156
replace year = 1998 in 157/168
replace year = 1999 in 169/180
replace year = 2000 in 181/192
replace year = 2001 in 193/204
replace year = 2002 in 205/216
replace year = 2003 in 217/228
replace year = 2004 in 229/240
replace year = 2005 in 241/252
replace year = 2006 in 253/264
replace year = 2007 in 265/276
replace year = 2008 in 277/288
replace year = 2009 in 289/300
replace year = 2010 in 301/312
replace year = 2011 in 313/324
replace year = 2012 in 325/336
replace year = 2013 in 337/348
replace year = 2014 in 349/360
replace year = 2015 in 361/372
replace year = 2016 in 373/384
replace year = 2017 in 385/396
replace year = 2018 in 397/408
replace year = 2019 in 409/420
replace year = 2020 in 421/432
replace year = 2021 in 433/437

gen month = 1 in 1
replace month = month[_n-1] + 1 in 2/12
replace month = 1 in 13
replace month = month[_n-1] + 1 in 14/24
replace month = 1 in 25
replace month = month[_n-1] + 1 in 26/36
replace month = 1 in 37
replace month = month[_n-1] + 1 in 38/48
replace month = 1 in 49
replace month = month[_n-1] + 1 in 50/60
replace month = 1 in 61
replace month = month[_n-1] + 1 in 62/72
replace month = 1 in 73
replace month = month[_n-1] + 1 in 74/84
replace month = 1 in 85
replace month = month[_n-1] + 1 in 86/96
replace month = 1 in 97
replace month = month[_n-1] + 1 in 98/108
replace month = 1 in 109
replace month = month[_n-1] + 1 in 110/120
replace month = 1 in 121
replace month = month[_n-1] + 1 in 122/132
replace month = 1 in 133
replace month = month[_n-1] + 1 in 134/144
replace month = 1 in 145
replace month = month[_n-1] + 1 in 146/156
replace month = 1 in 157
replace month = month[_n-1] + 1 in 158/168
replace month = 1 in 169
replace month = month[_n-1] + 1 in 170/180
replace month = 1 in 181
replace month = month[_n-1] + 1 in 182/192
replace month = 1 in 193
replace month = month[_n-1] + 1 in 194/204
replace month = 1 in 205
replace month = month[_n-1] + 1 in 206/216
replace month = 1 in 217
replace month = month[_n-1] + 1 in 218/228
replace month = 1 in 229
replace month = month[_n-1] + 1 in 230/240
replace month = 1 in 241
replace month = month[_n-1] + 1 in 241/252
replace month = 1 in 253
replace month = month[_n-1] + 1 in 254/264
replace month = 1 in 265
replace month = month[_n-1] + 1 in 266/276
replace month = 1 in 277
replace month = month[_n-1] + 1 in 278/288
replace month = 1 in 289
replace month = month[_n-1] + 1 in 290/300
replace month = 1 in 301
replace month = month[_n-1] + 1 in 302/312
replace month = 1 in 313
replace month = month[_n-1] + 1 in 314/324
replace month = 1 in 325
replace month = month[_n-1] + 1 in 326/336
replace month = 1 in 337
replace month = month[_n-1] + 1 in 338/348
replace month = 1 in 349
replace month = month[_n-1] + 1 in 350/360
replace month = 1 in 361
replace month = month[_n-1] + 1 in 362/372
replace month = 1 in 373
replace month = month[_n-1] + 1 in 374/384
replace month = 1 in 385
replace month = month[_n-1] + 1 in 386/396
replace month = 1 in 397
replace month = month[_n-1] + 1 in 398/408
replace month = 1 in 409
replace month = month[_n-1] + 1 in 410/420
replace month = 1 in 421
replace month = month[_n-1] + 1 in 422/432
replace month = 1 in 433
replace month = month[_n-1] + 1 in 434/437
gen ob_date = year + (month/12)

* Step 3: Create Graph and Save
binscatter Close ob_date if year >= 1990 & year < 1999, n(120) line(connect) xline(1993.92) ytitle(S&P TSE Index) xtitle(Year) xlabel(1990(1)1999) ylabel(2000(1000)8000)
graph export "$dir_graphs/Figure_E5c.pdf",  replace



ssc install binscatter
clear
import excel "$dir_outputs/Canada_10YrBond_IRLTLT01CAM156N.xls", sheet("FRED Graph") firstrow

* Step 2: Create/Rename Time and Dependent Variables
gen ob_date = year + (month/12)
rename IRLTLT01CAM156N Yield

* Step 3: Create Graph and Save
binscatter Yield ob_date if year >= 1990 & year < 1999, n(120) line(connect) xline(1993.92) ytitle(Yield (percent)) xtitle(Year) xlabel(1990(1)2000) ylabel(4(1)12)
graph export "$dir_graphs/Figure_E5d.pdf", replace



*----------------------   Figure E.6   -------------------*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_E_for_release.xlsx", sheet("Figure_E6") firstrow
****************************************************************************

foreach var in  clkgxi_dummy_wgt    {
replace `var'=`var'*100
}

*
foreach var in rclkgxi_wgt rpos_clkgxi_wgt      {
replace `var'=`var'/1.5
}

destring year_relative_to_over_LCGE, replace

lab var rpos_clkgxi_wgt "capital gains (1993 $)"
lab var rclkgxi_wgt "capital gains (1993 $)"
lab var clkgxi_dummy_wgt "% with positive net capital gains"



foreach var in rclkgxi_wgt rpos_clkgxi_wgt clkgxi_dummy_wgt {

twoway  connected `var' year_relative_to_over_LCGE if  cg_8593==2 , color(navy) msymbol(T)  ///
  xtitle("year relative to crossing LCGE") 
	graph export  "$dir_graphs/Figure_E6_`var'.pdf", replace
	
}

*----------------------   Figure F.1 (in dollars)  -------------------*



clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F1a") firstrow
****************************************************************************


foreach cg_8593_2 in 3 4 5  {
	foreach version in 2  {
if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta}CG)")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F1_cg`cg_8593_2'.pdf", replace		

}
}


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F1b") firstrow
****************************************************************************


	foreach version in 4  {
foreach cg_8593_2 in 3 4 5  {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta}CG)")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F1mod_v`version'_cg`cg_8593_2'.pdf", replace		

	
		twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta}CG)")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F1mod_v`version'_cg`cg_8593_2'.pdf", replace		

}
}


*----------------------  Figure F.2A (main extensive with indiv f.e.)   -------------------*

*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F2a") firstrow
****************************************************************************



foreach cg_8593_2 in 3 4 5  {
	foreach version in   4 {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)")  ylabel(-0.05(0.025)0.125, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F2A_cg`cg_8593_2'.pdf", replace

		

}
}

*----------------------  Figure F.2B (main with indiv f.e.)  -------------------*


*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F2b") firstrow
****************************************************************************


foreach cg_8593_2 in 3 4 5  {
	foreach version in  4 {
if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(-0.25(0.25)1.25, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F2B_cg`cg_8593_2'.pdf", replace
		
}
}


*----------------------  Figure F.3A (income controls extensive)   -------------------*


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F3a") firstrow
****************************************************************************



foreach cg_8593_2 in 3 4 5  {
	foreach version in  21 {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}


	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)")  ylabel(-0.05(0.025)0.125, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F3A_cg`cg_8593_2'.pdf", replace
}		
}



*----------------------   Figure  F.3B (income controls intensive)  -------------------*


*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F3b") firstrow
****************************************************************************


foreach cg_8593_2 in 3 4 5  {
	foreach version in  21 {
if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(-0.25(0.25)1.25, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F3B_cg`cg_8593_2'.pdf", replace


		
}
}

*---------------------- Figure F.4A (lifecycle extensive)  -------------------*




clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F4a") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in  24  {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)") ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F4A_cg`cg_8593_2'.pdf", replace
	
}
}



*---------------------- Figure F.4B (lifecycle intensive)  -------------------*




clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F4b") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in 24  {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F4B_cg`cg_8593_2'.pdf", replace
	
}
}

*---------------------- Figure F.5A,B,C (varying control group definition extensive)  -------------------*




clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F5_PanelA_extensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in  2  {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)") ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F5A_ext_cg`cg_8593_2'.pdf", replace
	
}
}

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F5_PanelB_extensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in  2  {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)") ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F5B_ext_cg`cg_8593_2'.pdf", replace
	
}
}


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F5_PanelC_extensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in  2  {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)") ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F5C_ext_cg`cg_8593_2'.pdf", replace
	
}
}


*---------------------- Figure F.5 (varying control group definition intensive)  -------------------*




clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F5_PanelA_intensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in 2 {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F5A_int_cg`cg_8593_2'.pdf", replace
	
}
}


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F5_PanelB_intensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in 2 {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F5B_int_cg`cg_8593_2'.pdf", replace
	
}
}


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F5_PanelC_intensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in 2  {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F5C_int_cg`cg_8593_2'.pdf", replace
	
}
}



*---------------------- Figure F.6A (1994 switchers extensive)  -------------------*



clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F6a") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in 2 {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'")  ytitle("coefficient estimates ({&Delta} probability)") ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F6A_cg`cg_8593_2'.pdf", replace
	
}
}




*---------------------- Figure F.6B (1994 switchers intensive)  -------------------*



clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F6b") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in 2 {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))") ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel( 1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F6B_cg`cg_8593_2'.pdf", replace
	
}
}




*---------------------- Figure F.7 (long windown extensive)  -------------------*





clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F7a") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in  1  {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(1984 1986 1988 1990 1992 1994 1996 1998  2000 2002 2004 2006) legend(off) 
	graph export  "$dir_graphs/Figure_F7A_cg`cg_8593_2'.pdf", replace
	
}
}




*---------------------- Figure F.7 (long windown intensive)  -------------------*



clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F7b") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in  1  {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'")  ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(1984 1986 1988 1990 1992 1994 1996 1998  2000 2002 2004 2006) legend(off) 
	graph export  "$dir_graphs/Figure_F7B_cg`cg_8593_2'.pdf", replace
	
}
}



*---------------------- Figure F.8A (age extensive)  -------------------*




clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_8_extensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in  2 3   {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)")   ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F8A_cg`cg_8593_2'_v`version'.pdf", replace
	
}
}



*---------------------- Figure F.8B (age intensive)  -------------------*



clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_8_intensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {
	foreach version in  2 3   {

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'")  ytitle("coefficient estimates ({&Delta} log(CG))")   ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F8B_cg`cg_8593_2'_v`version'.pdf", replace
	
}
}


*---------------------- Figure F.9 A  (married extensive)  -------------------*


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F9_extensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {

	foreach version in  2 3  {

if `cg_8593_2'==5{
local title  "Treatment group: 17-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)")  ylabel(-0.05(0.025)0.125, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F9A_cg`cg_8593_2'_v`version'.pdf", replace


}
}

*----------------------  Figure F.9 B (married intensive)  -------------------*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F9_intensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {

	foreach version in  2 3  {

if `cg_8593_2'==5{
local title  "Treatment group: 17-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F9B_cg`cg_8593_2'_v`version'.pdf", replace


	}
}






*---------------------- Figure F.10 A  (gender extensive)  -------------------*


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F10_extensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {

	foreach version in  2 3  {

if `cg_8593_2'==5{
local title  "Treatment group: 17-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)")  ylabel(-0.05(0.025)0.125, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F10A_cg`cg_8593_2'_v`version'.pdf", replace


}
}

*----------------------  Figure F.10 B (gender intensive)  -------------------*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F10_intensive") firstrow
****************************************************************************


foreach cg_8593_2 in 5 4 3 {

	foreach version in  2 3  {

if `cg_8593_2'==5{
local title  "Treatment group: 17-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_F10B_cg`cg_8593_2'_v`version'.pdf", replace


	}
}



*---------------------- Figure F.11 (drop business incomes extensive)  -------------------*




clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F11a") firstrow
****************************************************************************


foreach cg_8593_2 in 3 4 5  {
	foreach version in 2  {
if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}


	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)") || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F11A_cg`cg_8593_2'.pdf", replace
		
}
}


*---------------------- Figure F.11 (drop business incomes intensive)  -------------------*


*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F11b") firstrow
****************************************************************************


foreach cg_8593_2 in 3 4 5  {
	foreach version in 2  {
if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(-0.25(0.25)1.25, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F11B_cg`cg_8593_2'.pdf", replace


}
}

*---------------------- Figure F.12 (marriage robustness extensive)  -------------------*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F12a") firstrow
****************************************************************************


foreach cg_8593_2 in 3 4 5  {
	foreach version in 2  {
if `cg_8593_2'==5{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 67K-133K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 133K-200K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)") || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F12A_cg`cg_8593_2'.pdf", replace
	
		
}
}
*---------------------- Figure F.12 (marriage robustness intensive)  -------------------*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F12b") firstrow
****************************************************************************


foreach cg_8593_2 in 3 4 5  {
	foreach version in 2  {
if `cg_8593_2'==5{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 67K-133K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 133K-200K  CG in 1985-1993 (1993$)"
}

	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(-0.25(0.25)1.25, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F12B_cg`cg_8593_2'.pdf", replace
		
}
}


*---------------------- Figure F.13 (marriage robustness extensive 2)  -------------------*


*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F13a") firstrow
****************************************************************************


foreach cg_8593_2 in 3 4 5  {
	foreach version in 2  {
if `cg_8593_2'==5{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 67K-133K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 133K-200K  CG in 1985-1993 (1993$)"
}



	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)") || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F13A_cg`cg_8593_2'.pdf", replace
		
}
}






*---------------------- Figure F.13 (marriage robustness intensive 2)  -------------------*


*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_F_for_release.xlsx", sheet("Figure_F13b") firstrow
****************************************************************************


foreach cg_8593_2 in 3 4 5  {
	foreach version in 2  {
if `cg_8593_2'==5{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==4{
local title  "Treatment group: 67K-133K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 133K-200K  CG in 1985-1993 (1993$)"
}



	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))")  ylabel(-0.25(0.25)1.25, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off)  xtitle("")
	graph export  "$dir_graphs/Figure_F13B_cg`cg_8593_2'.pdf", replace


		
}
}



*---------------------- Figure G1 and G3   -------------------*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_G_for_release.xlsx", sheet("Figure_G1") firstrow
****************************************************************************

sort  year
merge n:1 year using "$dir_outputs/inflation.dta"
keep if _merge==1 | _merge==3
drop _merge



lab var age "average age" 
lab var married "share married"
lab var tnkid "number of children"
lab var rtirc "gross income in 1993$"
lab var rtxi "taxable income in 1993$"


sort  year
merge n:1 year using "$dir_outputs/TSEIndex_merge.dta"
keep if _merge==1 | _merge==3
drop _merge
lab var tsx "S&P TSE Index"
replace tsx=tsx*cpi_to2016



gen age_93 = age_wgt-(year-1993)
lab var age_93 "average age in 1993" 
replace rtirc=rtirc/1.5
replace rtxi=rtxi/1.5
replace tsx=tsx/1.5


foreach var in age_wgt married tnkid rtirc rtxi     {

twoway connected  `var' year if cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(0.75)|| connected  `var' year if cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(0.75) || connected  `var' year if cg_8593==4, color(blue)msymbol(T) msize(0.75) || connected  `var' year if cg_8593==5, color(ebblue) msymbol(S)  msize(0.75)  msymbol(D) xline(1985 1994, lpattern(-) lcolor(red))   graphregion(color(white)) bgcolor(white) xlabel( 1982 1985  1990  1994   2000 2005 2010 2015) legend(order(1 "100K-133K" 2 "67K-100K" 3 "33.33K-67K" 4 "17K-33K"   ) ring(1) col(4) row(1) pos(6))
graph export  "$dir_graphs/Figure_G1_`var'.pdf", replace

}


* repeat but as percent of 1995 values:

sort year cg_8593
foreach var in age_wgt married_wgt tnkidi_wgt rtirc_i rtxi__i tsx  {
gen `var'82=`var' if year==1995
bysort cg_8593: egen `var'_82=max(`var'82)
gen pc_`var'=`var'/`var'_82*100
drop `var'82 `var'_82
}
sort year cg_8593
lab var pc_rtirc "gross income as percent of 1995 value"
lab var pc_rtxi "taxable income as percent of 1995 value"


foreach var in  rtirc_i rtxi__i {

twoway connected  pc_`var' year if cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(0.75)|| connected  pc_`var' year if cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(0.75) || connected  pc_`var' year if cg_8593==4, color(blue)msymbol(T) msize(0.75) ///
 || connected  pc_`var' year if cg_8593==5, color(ebblue) msymbol(S)  msize(0.75)  msymbol(D) xline(1985 1994, lpattern(-) lcolor(red))  ///
 ||  line pc_tsx year if cg_8593==5, color(gray) lpattern(-)  graphregion(color(white)) bgcolor(white) xlabel( 1982 1985  1990  1994   2000 2005 2010 2015) legend(order(1 "100K-133K" 2 "67K-100K" 3 "33.33K-67K" 4 "17K-33K" 5 "S&P TSE"  )ring(1) col(4) row(1) pos(6))
graph export  "$dir_graphs/Figure_G3_`var'.pdf", replace

}


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_G_for_release.xlsx", sheet("Figure_G1_tirc_i_mius_clkgxi") firstrow
****************************************************************************

sort  year
merge n:1 year using "$dir_outputs/inflation.dta"
keep if _merge==1 | _merge==3
drop _merge

lab var rtot_income_less_cg "gross income minus CGs in 1993$"

sort  year
merge n:1 year using "$dir_outputs/TSEIndex_merge.dta"
keep if _merge==1 | _merge==3
drop _merge
lab var tsx "S&P TSE Index"
replace tsx=tsx*cpi_to2016

replace rtot_income_less_cg=rtot_income_less_cg/1.5
replace tsx=tsx/1.5

foreach var in rtot_income_less_cg     {

twoway connected  `var' year if cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(0.75)|| connected  `var' year if cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(0.75) || connected  `var' year if cg_8593==4, color(blue)msymbol(T) msize(0.75) || connected  `var' year if cg_8593==5, color(ebblue) msymbol(S)  msize(0.75)  msymbol(D) xline(1985 1994, lpattern(-) lcolor(red))   graphregion(color(white)) bgcolor(white) xlabel( 1982 1985  1990  1994   2000 2005 2010 2015) legend(order(1 "100K-133K" 2 "67K-100K" 3 "33.33K-67K" 4 "17K-33K"   ) ring(1) col(4) row(1) pos(6))
graph export  "$dir_graphs/Figure_G1_`var'.pdf", replace

}


* repeat but as percent of 1995 values:

sort year cg_8593
foreach var in rtot_income_less_cg tsx  {
gen `var'82=`var' if year==1995
bysort cg_8593: egen `var'_82=max(`var'82)
gen pc_`var'=`var'/`var'_82*100
drop `var'82 `var'_82
}
sort year cg_8593
lab var pc_rtot_income_less_cg "gross income minus CG as percent of 1995 value"



foreach var in  rtot_income_less_cg  {

twoway connected  pc_`var' year if cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(0.75)|| connected  pc_`var' year if cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(0.75) || connected  pc_`var' year if cg_8593==4, color(blue)msymbol(T) msize(0.75) ///
 || connected  pc_`var' year if cg_8593==5, color(ebblue) msymbol(S)  msize(0.75)  msymbol(D) xline(1985 1994, lpattern(-) lcolor(red))  ///
 ||  line pc_tsx year if cg_8593==5, color(gray) lpattern(-)  graphregion(color(white)) bgcolor(white) xlabel( 1982 1985  1990  1994   2000 2005 2010 2015) legend(order(1 "100K-133K" 2 "67K-100K" 3 "33.33K-67K" 4 "17K-33K" 5 "S&P TSE"  )ring(1) col(4) row(1) pos(6))
graph export  "$dir_graphs/Figure_G3_`var'.pdf", replace

}




*---------------------- Figure G2  and G3 -------------------*

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_G_for_release.xlsx", sheet("Figure_G2") firstrow
****************************************************************************

sort  year
merge n:1 year using "$dir_outputs/inflation.dta"
keep if _merge==1 | _merge==3
drop _merge


sort  year
merge n:1 year using "$dir_outputs/TSEIndex_merge.dta"
keep if _merge==1 | _merge==3
drop _merge
lab var tsx "S&P TSE Index"
replace tsx=tsx*cpi_to2016


lab var pos_age "average age" 
lab var pos_married "share married"
lab var pos_tnkid "number of children"
lab var rpos_tirc "gross income in 1993$"
lab var rpos_txi "taxable income in 1993$"


gen age_93 = pos_age_wgt-(year-1993)
lab var age_93 "average age in 1993" 
replace rpos_tirc=rpos_tirc/1.5
replace rpos_txi=rpos_txi/1.5
replace tsx=tsx/1.5

 

foreach var in  pos_age_wgt pos_married pos_tnkid rpos_tirc rpos_txi  {

twoway connected  `var' year if cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(0.75)|| connected  `var' year if cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(0.75) || connected  `var' year if cg_8593==4, color(blue)msymbol(T) msize(0.75) || connected  `var' year if cg_8593==5, color(ebblue) msymbol(S)  msize(0.75)  msymbol(D) xline(1985 1994, lpattern(-) lcolor(red))   graphregion(color(white)) bgcolor(white) xlabel( 1982 1985  1990  1994   2000 2005 2010 2015) legend(order(1 "100K-133K" 2 "67K-100K" 3 "33.33K-67K" 4 "17K-33K"   ) ring(1) col(4) row(1) pos(6))
graph export  "$dir_graphs/Figure_G2_`var'.pdf", replace

}


* repeat but as percent of 1982 values:

sort year cg_8593
foreach var in  pos_age_wgt pos_married_wgt pos_tnkidi_wgt rpos_tirc_i rpos_txi__i tsx   {
gen `var'82=`var' if year==1995
bysort cg_8593: egen `var'_82=max(`var'82)
gen pc_`var'=`var'/`var'_82*100
drop `var'82 `var'_82
}
sort year cg_8593
lab var pc_pos_age_wgt "average age as percent of 1995 value" 
lab var pc_pos_married "share married  as percent of 1995 value"
lab var pc_pos_tnkid "number of children  as percent of 1995 value"
lab var pc_rpos_tirc "gross income as percent of 1995 value"
lab var pc_rpos_txi "taxable income as percent of 1995 value"

*clkgxi_dummy_wgt age_93     rclkgxi log_clkgxi_wgt   mtr_wgt mtr_zero_wgt mtr_max_wgt 
foreach var in  rpos_tirc_i rpos_txi__i {

twoway connected  pc_`var' year if cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(0.75)|| connected  pc_`var' year if cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(0.75) || connected  pc_`var' year if cg_8593==4, color(blue)msymbol(T) msize(0.75) || connected  pc_`var' year if cg_8593==5, color(ebblue) msymbol(S)  msize(0.75)  msymbol(D) ///
||  line pc_tsx year if cg_8593==5, color(gray) lpattern(-)  xline(1985 1994, lpattern(-) lcolor(red))    graphregion(color(white)) bgcolor(white) xlabel( 1982 1985  1990  1994   2000 2005 2010 2015) legend(order(1 "100K-133K" 2 "67K-100K" 3 "33.33K-67K" 4 "17K-33K" 5 "S&P TSE"   )ring(1) col(4) row(1) pos(6))
graph export   "$dir_graphs/Figure_G3_`var'.pdf", replace

}

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_G_for_release.xlsx", sheet("Figure_G1_tirc_i_mius_clkgxi") firstrow
****************************************************************************

sort  year
merge n:1 year using "$dir_outputs/inflation.dta"
keep if _merge==1 | _merge==3
drop _merge


sort  year
merge n:1 year using "$dir_outputs/TSEIndex_merge.dta"
keep if _merge==1 | _merge==3
drop _merge
lab var tsx "S&P TSE Index"
replace tsx=tsx*cpi_to2016


lab var rpos_tot_income_less_cg "gross income minus CG in 1993$"

replace rpos_tot_income_less_cg=rpos_tot_income_less_cg/1.5
replace tsx=tsx/1.5

 

foreach var in  rpos_tot_income_less_cg {

twoway connected  `var' year if cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(0.75)|| connected  `var' year if cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(0.75) || connected  `var' year if cg_8593==4, color(blue)msymbol(T) msize(0.75) || connected  `var' year if cg_8593==5, color(ebblue) msymbol(S)  msize(0.75)  msymbol(D) xline(1985 1994, lpattern(-) lcolor(red))   graphregion(color(white)) bgcolor(white) xlabel( 1982 1985  1990  1994   2000 2005 2010 2015) legend(order(1 "100K-133K" 2 "67K-100K" 3 "33.33K-67K" 4 "17K-33K"   ) ring(1) col(4) row(1) pos(6))
graph export  "$dir_graphs/Figure_G2_`var'.pdf", replace

}


* repeat but as percent of 1982 values:

sort year cg_8593
foreach var in  rpos_tot_income_less_cg tsx   {
gen `var'82=`var' if year==1995
bysort cg_8593: egen `var'_82=max(`var'82)
gen pc_`var'=`var'/`var'_82*100
drop `var'82 `var'_82
}
sort year cg_8593
lab var rpos_tot_income_less_cg "gross income minus CG as percent of 1995 value"


*clkgxi_dummy_wgt age_93     rclkgxi log_clkgxi_wgt   mtr_wgt mtr_zero_wgt mtr_max_wgt 
foreach var in  rpos_tot_income_less_cg  {

twoway connected  pc_`var' year if cg_8593==2, color(navy) ylabel(, ang(h)) lpattern(-)  msymbol(Oh) msize(0.75)|| connected  pc_`var' year if cg_8593==3, color(eltblue) color(navy) msymbol(O) msize(0.75) || connected  pc_`var' year if cg_8593==4, color(blue)msymbol(T) msize(0.75) || connected  pc_`var' year if cg_8593==5, color(ebblue) msymbol(S)  msize(0.75)  msymbol(D) ///
||  line pc_tsx year if cg_8593==5, color(gray) lpattern(-)  xline(1985 1994, lpattern(-) lcolor(red))    graphregion(color(white)) bgcolor(white) xlabel( 1982 1985  1990  1994   2000 2005 2010 2015) legend(order(1 "100K-133K" 2 "67K-100K" 3 "33.33K-67K" 4 "17K-33K" 5 "S&P TSE"   )ring(1) col(4) row(1) pos(6))
graph export   "$dir_graphs/Figure_G3_`var'.pdf", replace

}

*---------------------- Figure H1   -------------------*


clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_H_for_release.xlsx", sheet("Figure_H1") firstrow
****************************************************************************


sort  year
merge n:1 year using "$dir_outputs/inflation.dta"
keep if _merge==1 | _merge==3
drop _merge

sort  year
merge n:1 year using "$dir_outputs/TSEIndex_merge.dta"
keep if _merge==1 | _merge==3
drop _merge
lab var tsx "S&P TSE Index"
replace tsx=tsx*cpi_to2016


foreach var in xdiv_i_dummy_wgt rrspci_dummy_wgt invi_i_dummy_wgt {
replace `var'=`var'*100
}


foreach var in rxdiv_i_wgt  rinvi_i_wgt   rrrspci_wgt rpos_xdiv_i_wgt rpos_invi_i_wgt rpos_rrspci_wgt tsx{
	replace `var'=`var'/1.5
}


lab var tsx "S&P TSE Index (1993 $)"
lab var xdiv_i_dummy_wgt "% with positive dividends"
lab var rrspci_dummy_wgt "% with positive RRSP contrubutions"
lab var invi_i_dummy_wgt "% with positive investment income"
*
lab var rxdiv_i_wgt "dividends (1993 $)"
lab var rrrspci_wgt "RRSP contributions (1993 $)"
lab var rinvi_i_wgt "investment income (1993 $)"
lab var rpos_xdiv_i_wgt "dividends (1993 $)"
lab var rpos_rrspci_wgt "RRSP contributions (1993 $)"
lab var rpos_invi_i_wgt "investment income (1993 $)"
*


foreach var in     rxdiv_i_wgt  rinvi_i_wgt   rrrspci_wgt rpos_xdiv_i_wgt rpos_invi_i_wgt rpos_rrspci_wgt {
twoway connected  `var' year, xline(1985 1994 ,  lcolor(red) lpattern(-))  graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2500)20000, axis(2)  ang(h)) legend( pos(6) ring(1) col(2))
graph export  "$dir_graphs/Figure_H1_`var'.pdf", replace
}

foreach var in    xdiv_i_dummy_wgt rrspci_dummy_wgt invi_i_dummy_wgt  {		
twoway connected  `var' year, xline(1985 1994 ,  lcolor(red) lpattern(-))  ylabel(0(5)50) graphregion(color(white)) bgcolor(white) xlabel(1982 1985 1990 1994 2000 2005 2010 2015) || line tsx year, lpattern(-) yaxis(2) lcolor(gs10)  ylabel(0(2500)20000, axis(2)  ang(h)) legend( pos(6) ring(1) col(2))
graph export  "$dir_graphs/Figure_H1_`var'.pdf", replace
}


*---------------------- Figure H.2 (other outcomes extensive)  -------------------*





foreach type in a_xdiv_i  b_invi_i  c_rrspci   {
	

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_H_for_release.xlsx", sheet("Figure_H2`type'_extensive") firstrow 
****************************************************************************



foreach cg_8593_2 in  5 4 3 {
	foreach version in 2{

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"

}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} probability)") ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_H2_`type'_cg`cg_8593_2'.pdf", replace
		
}
}
}





*---------------------- Figure H.3 (other outcomes intensive)  -------------------*


foreach type in   a_xdiv_i  b_invi_i  c_rrspci {
	

clear
****************************************************************************
import excel "$dir_outputs/RESTAT_Online_Appendix_H_for_release.xlsx", sheet("Figure_H3`type'_intensive") firstrow 
****************************************************************************



foreach cg_8593_2 in  5 4 3 {
	foreach version in 2{

if `cg_8593_2'==5{
local title  "Treatment group: 17K-33K  CG in 1985-1993 (1993$)"

}
if `cg_8593_2'==4{
local title  "Treatment group: 33K-67K  CG in 1985-1993 (1993$)"
}
if `cg_8593_2'==3{
local title  "Treatment group: 67K-100K  CG in 1985-1993 (1993$)"
}
	twoway connected b year if cg_8593_2==`cg_8593_2'   & version==`version', yline(0, lcolor(gray)) title("`title'") ytitle("coefficient estimates ({&Delta} log(CG))") ylabel(, ang(h)) || line lb year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-) || line ub year if cg_8593_2==`cg_8593_2'  & version==`version', lcolor(gray) lpattern(-)  xline(1994, lcolor(red)) graphregion(color(white)) bgcolor(white) xlabel(  1990 1992 1994 1996 1998  2000) legend(off) 
	graph export  "$dir_graphs/Figure_H3_`type'_cg`cg_8593_2'.pdf", replace
		
}
}
}

